package com.qianfeng.test;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.RadioGroup;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.qianfeng.test.adapter.MenuAdapter;
import com.qianfeng.test.bean.menu_bean.ListEntity;
import com.qianfeng.test.constants.UrlConstans;
import com.qianfeng.test.fragment.GroupBuyFragment;
import com.qianfeng.test.fragment.MeFragment;
import com.qianfeng.test.fragment.MoreFragment;
import com.qianfeng.test.fragment.SellerFragment;
import com.qianfeng.test.task.MenuTask;
import com.qianfeng.test.utils.FragmentTabUtils;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{


    private SlidingMenu menu;
    private RadioGroup rgs;
    private MenuAdapter menuAdapter;
    private List<ListEntity> listEntitys = new ArrayList<ListEntity>();
    private ListView menuListView;
    private List<Fragment> fragments = new ArrayList<Fragment>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        System.out.print("MainActivity....进来了");
        initMenu();
        initView();

     }

    private void initMenu() {
        menu = new SlidingMenu(this);
        menu.setMode(SlidingMenu.LEFT);
        /*
        *触摸模式的三种
        * SlidingMenu.TOUCH_FULLSCREEN 全屏触摸侧滑
        * *SlidingMenu.TOUCHMODE_MARGIN 边缘触摸侧滑(解决手势冲突)
         *SlidingMenu.TOUCHMODE_NONE 不可以通过触摸侧滑
         */
        menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
        //设置侧滑菜单的宽度
        menu.setBehindOffsetRes(R.dimen.menu_offset_with);
        /*
        *设置显示的内容view
         */
        menu.setMenu(R.layout.menu_left_layout);

        menu.attachToActivity(this,SlidingMenu.SLIDING_WINDOW);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        menuListView = (ListView)findViewById(R.id.menu_listView);
        menuAdapter = new MenuAdapter(listEntitys,this);
        menuListView.setAdapter(menuAdapter);
        MenuTask menuTask = new MenuTask(menuAdapter,listEntitys);
//        menuTask.setOnMenuDownLoadEnd(new MenuTask.MenuDownLoadEnd() {
//            @Override
//            public void onMenuDownLoadEnd() {
//
//                menuAdapter.notifyDataSetChanged();
//            }
//        });
        menuTask.execute(UrlConstans.Url_Menu);

    }
    private void initView(){

        rgs = (RadioGroup) this.findViewById(R.id.main_rgs);
        fragments.add(new GroupBuyFragment());
        fragments.add(new SellerFragment());
        fragments.add(new MeFragment());
        fragments.add(new MoreFragment());
        FragmentTabUtils utils =
                new FragmentTabUtils( getSupportFragmentManager(),fragments, R.id.fragment_main_container,rgs);

        utils.setOnRgsExtraCheckedChangedListener(new FragmentTabUtils.OnRgsExtraCheckedChangedListener() {
            @Override
            public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId, int index) {
                //

            }
        });


    }



    @Override
    public void onClick(View v) {

    }



}
